define(function(require, exports){
	var $ = require("jquery");
	var pubjs = require('pubjs');
	var view = require('@base/view');
	var util = require('util');
	var dspUtil = require('dspUtil');
	var Edit = require('@mod/fieldEdit').base;

	exports.base = Edit.extend({
		init:function(config){
			config = pubjs.conf(config, {
				nav: 'adExchange',
				fields: [
					{text: LANG('新建or编辑'), tip: LANG('对权值设新值还是编辑'), type: 'radio', field: 'isNew', validate: true,
						items: [
							{
								id: 1,
								name: LANG('新建')
							}
							,{
								id: 0,
								name: LANG('编辑')
							}
						]
					}
					,{text: LANG('属性'), tip: LANG('权值的字段'), type: 'input', field: 'new_attr', width: 500}
					,{'text': '属性', tip: LANG('标识要设的的渠道的权值属性'), type: 'dropdown', field: 'old_attr', validate: true, 'config': {
						'title': LANG('属性'),
						'url': 'adexchange/weightAttr',
						'reqType': 'websocket',
						'key': 'Name',
						'def': '请选择属性',
						'name': 'Name'
					}}
					,{text: LANG('渠道权值编辑'), tip: LANG('设置权值'), width: 500,
						type: 'custom', uri: 'adExchange/module/weight.input',
						field: 'data', validate: true
					}
				],
				Title: LANG('权值设置:'),
				urlAdd: 'adexchange/weightUpdate'
			});

			this.Super('init', arguments);
		}
		,reset: function() {
			this.Super('reset', arguments);
			this.set_field('isNew', '1');
			this.$.old_attr && this.$.old_attr.reload();
			this.$.old_attr && this.$.old_attr.reset();
			this.$.data && this.$.data.reset();
			return this;
		}
		,dataChange: function(field, v) {
			this.Super('dataChange', arguments);
			switch (field) {
				case 'isNew':
					v = +v;
					this.toggle('new_attr', !!v);
					this.toggle('old_attr', !v);
					if(!v)
					{
						var f = this.$.old_attr.getData();
						if(f){
							this.$.data.changeField(f);
						}
					}
					else
					{
						this.$.data && this.$.data.empty();
					}
					break;
				case 'old_attr':
					var mod = this.$.data;
					mod && mod.changeField(v);
					break;
			}
		}
		,setData: function() {
			this.Super('setData', arguments);
			//this.disable(['type', 'field']);
			return this;
		}

	});

});